package com.ty.sso.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ty.sso.vo.User;

public interface UserMapper {

    @Select("SELECT * FROM user")
    @Results({
        @Result(property = "userId",  column = "user_id"),
        @Result(property = "userName", column = "user_name"),
        @Result(property = "userPassword", column = "user_password"),
        @Result(property = "userEmail", column = "user_email")
    })
    List<User> getAll();

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    @Results({
        @Result(property = "userId",  column = "user_id"),
        @Result(property = "userName", column = "user_name"),
        @Result(property = "userPassword", column = "user_password"),
        @Result(property = "userEmail", column = "user_email")
    })
    User getOneById(Long userId);
    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    @Results({
        @Result(property = "userId",  column = "user_id"),
    	@Result(property = "userName", column = "user_name"),
    	@Result(property = "userPassword", column = "user_password"),
    	@Result(property = "userEmail", column = "user_email")
    })
    User getOneByName(String userName);

    @Insert("INSERT INTO user(user_name,user_password,user_email) VALUES(#{userName}, #{userPassword}, #{userEmail})")
    void insert(User user);

    @Update("UPDATE user SET user_name=#{userName},user_password=#{userPassword},user_email=#{userEmail} WHERE user_id =#{userId}")
    void update(User user);

    @Delete("DELETE FROM user WHERE user_id =#{userId}")
    void delete(Long id);

}
